package cn.stronglink.assetmanage.business.inspection.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;

import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.entity.Patrol;
import cn.stronglink.assetmanage.index.view.onRecyclerListener;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * 巡检列表
 * Created by zhengjinglan on 2018/6/16.
 */

public class PatrolListAdapter extends RecyclerView.Adapter<PatrolListAdapter.ViewHolder>{

    private Context mcontext;
    private List<Patrol> datas;
    private onRecyclerListener listener;

    public PatrolListAdapter(Context context){
        this.mcontext = context;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view =LayoutInflater.from(mcontext).inflate(R.layout.item_repair_list,parent,false);
        return new ViewHolder(view,listener);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Patrol patrol = datas.get(position);
        holder.bindRepo(patrol, position);
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public void setOnItemClickListener(onRecyclerListener listener){
        this.listener = listener;
    }

    public void notifyDatasChanged(List<Patrol> data){
        this.datas =  data;
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        private TextView tv_patrol_id,tv_patrol_type;

        private onRecyclerListener listener;
        public ViewHolder(View itemView,onRecyclerListener listener) {
            super(itemView);
            this.listener = listener;
            tv_patrol_id = (TextView)itemView.findViewById(R.id.tv_repair_id);
            tv_patrol_type=itemView.findViewById(R.id.tv_repair_type);
            itemView.setOnClickListener(this);
        }

        public void bindRepo(Patrol repo, int position){
            tv_patrol_id.setText(repo.getId_());
            String type = "";
            int status = repo.getType();
            if(status == Constants.STATUS_THREE){
                type = mcontext.getResources().getString(R.string.common_patrol);
            }else {
                type = mcontext.getResources().getString(R.string.common_unpatrol);
            }

        }
        @Override
        public void onClick(View v) {
            if (listener != null){
                listener.onItemClicked(v, getAdapterPosition());
            }
        }
    }
}
